package com.yuyu.shop.infrastructure.persistence.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yuyu.shop.domain.marketing.DO.ActivityDO;
import com.yuyu.shop.domain.marketing.repository.ActivityRepository;
import com.yuyu.shop.infrastructure.persistence.convert.ActivityPoConvert;
import com.yuyu.shop.infrastructure.persistence.mapper.ActivityMapper;
import com.yuyu.shop.infrastructure.persistence.po.ActivityPO;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author
 * @version 1.0
 * @description: TODO
 * @date 2022/8/4 17:39
 */
@RequiredArgsConstructor(onConstructor = @_(@Autowired))//不需要加注解注入
@Service
public class ActivityRepositoryImpl implements ActivityRepository {
    private final ActivityMapper activityMapper;
    @Override
    public List<ActivityDO> getByGoodsId(Long goodsId) {
        List<ActivityPO> activityPO = activityMapper.selectList(new LambdaQueryWrapper<ActivityPO>().eq(ActivityPO::getGoodsId, goodsId));
        return activityPO.stream().map(ActivityPoConvert::PO2DO).collect(Collectors.toList());
    }
}
